import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { PageContainer } from '@ant-design/pro-layout';
import { useRef } from 'react';
import { useParams } from '@umijs/max';
import {
  ProTable,
} from '@ant-design/pro-components';
import { Button} from 'antd';
import {  get_list_api } from './api';

export default function Page() {
  const ref = useRef<ActionType>();
  const paramsd = useParams();
  const columns: ProColumns<UserApi.UserList>[] = [
    // {
    //   dataIndex: 'index',
    //   valueType: 'indexBorder',
    //   width: 48,
    // },

    {
      title: '姓名',
      width: 160,
      dataIndex: 'trueName',
    },
    {
      title: '所属部门',
      search: false,
      dataIndex: 'suoDeft',
    },
    {
      title: '报名时间',
      search: false,
      dataIndex: 'bmTime',
    },
    {
      title: '签到时间',
      search: false,
      dataIndex: 'signTime',
    }
  ];

  return (
    <PageContainer>
      <ProTable<UserApi.UserList>
        actionRef={ref}
        request={async (params = {}) => {
          const columnFilters: any = {};
          Object.keys(params).forEach((key) => {
            if (key !== 'current' && key !== 'pageSize') {
              columnFilters[key] = {
                eq: '%',
                name: key,
                value: params[key],
              };
            }
          });
          const res = await get_list_api({
            columnFilters: columnFilters,
            pageNum: params?.current ?? 1,
            pageSize: params?.pageSize ?? 10,
            id:""+paramsd.id
          });

          return {
            page: params?.current,
            data: res.data.records,
            success: true,
            total: res.data.total,
          };
        }}
        rowKey="id"
        pagination={{
          pageSize: 10,
        }}
        columns={columns}
        dateFormatter="string"
        toolBarRender={() => [
            // eslint-disable-next-line react/jsx-key
            <Button  onClick={() => {
              //open('/sys/User')
              history.back();
           }}>返回</Button>
        ]}
      />
    </PageContainer>
  );
}
